﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Assignment2
{
    class KeyboardHandler
    {
        private static KeyboardState keyState;
        private static KeyboardState oldKeyState;

        private static int countSpacebar = 0;
        public static int CountSpacebar { get { return countSpacebar; } }

        private static float angle = 0.05f;

        //init keyboard state
        public static void InitKeyboard()
        {
            keyState = Keyboard.GetState();
        }

        //listen to spacebar
        public static void SpacebarListener()
        {
            if (keyState.IsKeyDown(Keys.Space) && oldKeyState.IsKeyUp(Keys.Space))
            {
                countSpacebar += 1;
            }
            oldKeyState = keyState;
        }

        //listen to move
        public static void KeyboardMoveListener(ref Vector2 stringPos)
        {
            if (keyState.IsKeyDown(Keys.Right))
            {
                stringPos.X += 5;
            }
            if (keyState.IsKeyDown(Keys.Down))
            {
                stringPos.Y += 5;
            }
            if (keyState.IsKeyDown(Keys.Left))
            {
                stringPos.X -= 5;
            }
            if (keyState.IsKeyDown(Keys.Up))
            {
                stringPos.Y -= 5;
            }
        }

        public static void KeyboardMoveListener(ref Matrix world)
        {

            if (keyState.IsKeyDown(Keys.E))
            {
                world *= Matrix.CreateRotationX(angle);
            }
            if (keyState.IsKeyDown(Keys.D))
            {
                world *= Matrix.CreateRotationX(-angle);
            }
            if (keyState.IsKeyDown(Keys.W))
            {
                world *= Matrix.CreateRotationY(angle);
            }
            if (keyState.IsKeyDown(Keys.S))
            {
                world *= Matrix.CreateRotationY(-angle);
            }
            if (keyState.IsKeyDown(Keys.Q))
            {
                world *= Matrix.CreateRotationZ(angle);
            }
            if (keyState.IsKeyDown(Keys.A))
            {
                world *= Matrix.CreateRotationZ(-angle);
            }
        }

    }
}
